package jdom;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;



public class TestJdomUtil {

	/**
	 * jdom测试类
	 */
	
	String site = null;
	
	public String getSite() {
		return site;
	}

	public String readrobot() {
		
		String xmlpath = "test.xml";
		SAXBuilder builder = new SAXBuilder(false);
		String spiderRegulation = null;
		try {
			Document doc = builder.build(xmlpath);
			Element books = doc.getRootElement();
			List booklist = books.getChildren("book");
			for (Iterator iter = booklist.iterator(); iter.hasNext();) {
				Element book = (Element) iter.next();
				spiderRegulation =book.getChildTextTrim("spiderRegulation");
				site = book.getChildText("site");
				System.out.println(spiderRegulation);
			}
			 
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return spiderRegulation;

	}

}
